package table;

import nodes.Type;
import visitors.SymbolTablePrettyPrintVisitor;

public final class VariableDeclaration extends Declaration
{
    private final Type type;
    private volatile int hashCode;

    public VariableDeclaration(Type type)
    {
        if (type == null)
        {
            throw new NullPointerException("Type cannot be null!");
        }
        this.type = type;
    }

    public Type getType()
    {
        return type;
    }

    @Override
    public boolean equals(Object aThat)
    {
        if (this == aThat) return true;
        return aThat.getClass() == getClass() &&
                ((VariableDeclaration) aThat).type.equals(type);
    }

    @Override
    public int hashCode()
    {
        int result = hashCode;
        if (result==0)
        {
            result = 17;
            result = 31 * result + type.hashCode();
            hashCode = result;
        }
        return result;
    }

    @Override
    public Object accept(SymbolTablePrettyPrintVisitor v)
    {
        return v.visit(this);
    }
}